﻿class com.spikything.utils.FPSMeter extends MovieClip {

	private var timeNow:Number, lastTime:Number;
	private var startTime:Number = getTimer();
	private var interval = 4;
	private var count = interval;
	private var output:TextField;
	private var bar:MovieClip;

	function FPSMeter () {
		output.autoSize = true;
		onEnterFrame = getFPS;
	}

	private function getFPS():Void {
		count = (count+1)%interval;
		lastTime = timeNow;
		timeNow = getTimer()-startTime;
		var fps = Math.round(1000/(timeNow-lastTime)); //(interval*1000)
		bar._xscale = fps;
		if (count==0) output.text = fps;
	}

}